<template>
	<el-form ref="form" :model="form" label-width="80px">
		<el-form-item label="合同编号">
			<el-input v-model="contract.code" disabled="true"></el-input>
		</el-form-item>
		<el-form-item label="合同名称">
			<el-input v-model="contract.name" disabled="true"></el-input>
		</el-form-item>
		<el-form-item label="合同金额">
			<el-input v-model="contract.amount" disabled="true"></el-input>
		</el-form-item>
		<el-form-item label="合同状态">
			<el-select v-model="contract.status">
				<el-option label="签订中" value="签订中"></el-option>
				<el-option label="待通过" value="待通过"></el-option>
				<el-option label="已通过" value="已通过"></el-option>
				<el-option label="已废除" value="已废除"></el-option>
			</el-select>
		</el-form-item>
		<el-form-item label="合同文件">
			<el-input v-model="contract.file" disabled="true"></el-input>
		</el-form-item>
		<el-form-item label="合同类型">
			<el-select v-model="contract.category">
				<el-option label="固定总价合同" value="固定总价合同"></el-option>
				<el-option label="买卖合同" value="买卖合同"></el-option>
				<el-option label="分包合同" value="分包合同"></el-option>
				<el-option label="计量合同" value="计量合同"></el-option>
			</el-select>
		</el-form-item>
		<el-form-item label="关联产品">
			<el-input v-model="contract.relatedProduct"></el-input>
		</el-form-item>
		<el-form-item label="签订人">
			<el-input v-model="contract.signedPerson" disabled="true"></el-input>
		</el-form-item>
		<el-form-item label="签订时间">
			<el-input v-model="contract.signedTime" disabled="true"></el-input>
		</el-form-item>
		<el-form-item label="到期时间">
			<el-input v-model="contract.expireTime" disabled="true"></el-input>
		</el-form-item>
		<el-form-item label="付款方式">
			<el-input v-model="contract.paymentWay" disabled="true"></el-input>
		</el-form-item>
		<el-form-item label="预付款">
			<el-input v-model="contract.advanceCharge" disabled="true"></el-input>
		</el-form-item>
		<el-form-item label="备注">
			<el-input type="textarea" v-model="contract.note"></el-input>
		</el-form-item>
		<el-form-item>
			<el-button type="primary" @click="onSubmit">修改合同信息</el-button>
			<el-button @click="back()">取消</el-button>
		</el-form-item>
	</el-form>
</template>


<script>
	export default {
		data() {
			return {
				userId: 0,
				contractId: 0,
				contract: {}
			}
		},
		onLoad(options) {
			this.userId = uni.getStorageSync('id')
			this.contractId = options.contractId;
			console.log(this.userId + ' ' + this.contractId);
			// 获取合同详细信息
			uni.request({
				url: 'http://localhost:8089/crmdemo/contract/queryContractInfoById', //仅为示例，并非真实接口地址。
				data: {
					contractId: this.contractId
				},
				success: (res) => {
					console.log(res);
					if (res.data.status == "000000") {
						this.contract = res.data.result
					} else {
						this.$modal.msgError("获取合同信息失败")
					}
				}
			});
		},
		methods: {
			onSubmit() {
				function timestampToTime(timestamp) {
					var date = new Date(timestamp); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
					var Y = date.getFullYear() + '-';
					var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
					var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
					var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
					var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
					var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
					return Y + M + D + h + m + s;
				}
				this.contract.signedTime = timestampToTime(this.contract.signedTime)
				this.contract.expireTime = timestampToTime(this.contract.expireTime)
				// 新增回款信息
				uni.request({
					url: 'http://localhost:8089/crmdemo/contract/updateContractInfo', //仅为示例，并非真实接口地址。
					data: {
						id: this.contractId,
						userId: this.userId,
						customId: this.contract.customId,
						code: this.contract.code,
						name: this.contract.name,
						amount: this.contract.amount,
						status: this.contract.status,
						file: this.contract.file,
						category: this.contract.category,
						relatedProduct: this.contract.relatedProduct,
						signedPerson: this.contract.signedPerson,
						signedTime: this.contract.signedTime,
						expireTime: this.contract.expireTime,
						paymentWay: this.contract.paymentWay,
						advanceCharge: this.contract.advanceCharge,
						note: this.contract.note,
						categorys: this.contract.categorys
					},
					success: (res) => {
						console.log(res);
						if (res.data.status == "000000") {
							uni.showToast({
								title: "修改合同信息成功",
								duration: 2000
							})
							setTimeout(() => {
								uni.reLaunch({
									url: 'contractDetail?contractId='+this.contractId
								})
							}, 2000)
						} else {
							this.$modal.msgError("修改合同信息失败")
						}
					}
				});
			},
			back(){
				uni.navigateTo({
					url: 'contractDetail?contractId='+this.contractId
				})
			}
		}
	}
</script>


<style>

</style>